package com.ebelter.seneo.ui.fragments.infos;


import android.graphics.Color;
import android.os.Bundle;
import android.widget.TextView;

import com.ebelter.btcomlib.common.IOrder;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserCurrentMeasureRecord;
import com.ebelter.btcomlib.models.db.products.seneo.SeneoUserinfos;
import com.ebelter.btcomlib.utils.NumUtils;
import com.ebelter.btcomlib.utils.ViewUtils;
import com.ebelter.seneo.R;
import com.ebelter.seneo.contants.IUserContant;
import com.ebelter.seneo.ui.fragments.BaseFragment;
import com.ebelter.seneo.ui.fragments.main.Dash_Fragment;
import com.ebelter.seneo.ui.fragments.main.Info_Fragment;
import com.ebelter.seneo.ui.views.LevelView;
import com.ebelter.seneo.utils.BodyCompositionCriteria;
import com.ebelter.seneo.utils.SeneoUtils;


//填写密码
public class Info_WeightControl_Fragment extends BaseFragment  implements Info_Fragment.IInfoUpdateInterface {


    public static final String TAG = "Info_WeightControl_Fragment";
    TextView infofly_value_tv;
    TextView infofly_valueunit_tv;
    TextView infofly_tip1_tv;
    LevelView info_levelview;

    @Override
    protected int setLayoutResouceId() {
        return R.layout.info_fly1;
    }

    @Override
    protected void initView() {
        FV();
    }

    private void FV() {
        infofly_value_tv=findViewById(R.id.infofly_value_tv);
        infofly_valueunit_tv=findViewById(R.id.infofly_valueunit_tv);
        infofly_tip1_tv=findViewById(R.id.infofly_tip1_tv);
        info_levelview=findViewById(R.id.info_levelview);
        ViewUtils.goneView(info_levelview);
        ViewUtils.setTextSize(infofly_value_tv,17);

        ViewUtils.goneView(infofly_valueunit_tv);
    }


    @Override
    protected void initData(Bundle arguments) {

        String tip=getString(R.string.info_weightcontrol_tip);
        infofly_tip1_tv.setText(tip);

        if (getParentFragment()!=null){
            ((Info_Fragment)getParentFragment()).getCurrentDisplayInfo(TAG);
        }

    }

    @Override
    public void UpdateCurrentMesureInfo(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        disWeightControl(currentUserinfos,currentMeasureRecord);
    }

    private void disWeightControl(SeneoUserinfos currentUserinfos, SeneoUserCurrentMeasureRecord currentMeasureRecord) {
        int unit = SeneoUtils.getUnitModel();

//        if (unit==0){
//            ViewUtils.setTextViewStr(infofly_valueunit_tv, IUserContant.IDIS.kg);
//        }else {
//            ViewUtils.setTextViewStr(infofly_valueunit_tv, IUserContant.IDIS.lb);
//        }

        if (currentMeasureRecord==null){
            ViewUtils.setTextViewStr(infofly_value_tv, IUserContant.IDIS.Non);
            return;
        }
        //String unitStr = (unit==0? IUserContant.IDIS.kg: IUserContant.IDIS.lb);
      //  float weightControl=currentMeasureRecord.weight- BodyCompositionCriteria.getWeightKgByBMI(24,currentUserinfos.height);
        float weightControl=currentMeasureRecord.weightControl;
       // String weightControlStr = NumUtils.numBaoLiuWei1(SeneoUtils.adapterDataFloat(weightControl,unit))+"";\
        //ViewUtils.setTextViewStr(infofly_value_tv, weightControlStr);
        ViewUtils.setTextViewStr(infofly_value_tv, getDesc(weightControl,unit));

    }


    private String getDesc(float weightControl,int unit){



        weightControl = SeneoUtils.adapterDataFloat(weightControl,unit);

        String unitStr=unit==0?" kg":" lb";

        if (weightControl==0){
            return "Standard";
        }else if (weightControl>0){
            return "Add "+Math.abs(NumUtils.numBaoLiuWei1(weightControl))+unitStr+" to achieve standard weight";
        }else if (weightControl<0){
            return "Lose "+Math.abs(NumUtils.numBaoLiuWei1(weightControl))+unitStr+" to achieve standard weight";
        }


        return "";
    }
}
